// #define print(...)

class Solution {
public:
ListNode* reverseKGroup(ListNode* head, int k) {
    if(k<=1) return head;
    ListNode emptyHead(0, head);
    auto before = &emptyHead; // 左边界
    while(auto after = before->next){
        for(int i=1;i<k;i++)
            if(!(after = after->next))
                return emptyHead.next;
        auto front = before->next, back = after;
        after = after->next; // 右边界
        back->next = NULL;
        tie(front, back) = reverseList(front, back);
        print("krev=", front, "\n")
        // 插入原链表
        before->next = front;
        back->next = after;
        // 调整左边界
        before = back;
    }
    return emptyHead.next;
}
};
